package com.chinawayltd.ews.sample.util.excel;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: g7ews4java-sample
 * @description: excel导出类
 * @author: xiazj
 * @create: 2018-04-13 16:15
 **/
public class ExcelGenerateModel {

    private static final String EXCEL_TYPE_XLS = "xls";
    private static final String EXCEL_TYPE_XLSX = "xlsx";

    private final List<ExportCloumsModel> cloumnList;
    private final List<Object> dataList;
    private final String excelVersion;
    private final String sheetName;

    private ExcelGenerateModel(Builder builder) {
        this.cloumnList = builder.cloumnList;
        this.dataList = builder.dataList;
        this.excelVersion = builder.excelVersion;
        this.sheetName = builder.sheetName;
    }

    public List<ExportCloumsModel> getCloumnList() {
        return cloumnList;
    }

    public List<Object> getDataList() {
        return dataList;
    }

    public String getSheetName() {
        return sheetName;
    }

    public String getExcelVersion() {
        return excelVersion;
    }

    public boolean is03Excel(){
        return excelVersion == EXCEL_TYPE_XLS;
    }

    public static class Builder {
        private List<ExportCloumsModel> cloumnList;
        private List<Object> dataList;
        private String excelVersion = EXCEL_TYPE_XLS;
        private String sheetName = "Sheet1";

        public Builder() {
        }

        public Builder(List dataList) {
            this.dataList = dataList;
        }

        public Builder(List dataList, String excelVersion) {
            this.dataList = dataList;
            this.excelVersion = excelVersion;
        }

        public Builder putCloumn(String title, String field){
            if(this.cloumnList == null){
                this.cloumnList = new ArrayList<>();
            }
            this.cloumnList.add(new ExportCloumsModel(title, field));
            return this;
        }

        public Builder cloumnList(List<ExportCloumsModel> cloumnList){
            this.cloumnList = cloumnList;
            return this;
        }

        public Builder dataList(List<Object> dataList){
            this.dataList = dataList;
            return this;
        }

        public Builder excelVersion(String excelVersion){
            this.excelVersion = excelVersion;
            return this;
        }

        public Builder sheetName(String sheetName){
            this.sheetName = sheetName;
            return this;
        }

        public ExcelGenerateModel build() { // 构建，返回一个新对象
            return new ExcelGenerateModel(this);
        }

    }

}
